<?php
include("../utility/connection.php");
include("../model/mUser.php");
session_start();

unset($_SESSION['seminarResult']);
unset($_SESSION['seminarUser']);
unset($_SESSION['setDaftar']);
unset($_SESSION['re-register']);
unset($_SESSION['topikId']);
unset($_SESSION['ubah']);
unset($_SESSION['ubahSeminar']);
unset($_SESSION['ubahUser']);
unset($_SESSION['userId']);
unset($_SESSION['uploadSukses']);
unset($_SESSION['uploadMessage']);
unset($_SESSION['userResult']);
unset($_SESSION['slctUser']);
unset($_SESSION['speakerId']);
unset($_SESSION['speakerResult']);
unset($_SESSION['MsgSent']);
unset($_SESSION['userResult']);
unset($_SESSION['topListResult']);
unset($_SESSION['Tujuan']);
unset($_SESSION['Pengirim']);
unset($_SESSION['Sms']);
unset($_SESSION['reportSMS']);
//session_destroy();
//session_unset();
        
if($_SERVER["REQUEST_METHOD"] == "POST") {
    $LoginId = trim(mysql_real_escape_string($_POST["txtLoginId"]));
    $Password = trim(mysql_real_escape_string($_POST["txtPassword"]));
    
    $result = fnLogin($LoginId, $Password);
    $count = mysql_num_rows($result); // number of row
    $arrResult = mysql_fetch_array($result);
    
    if ($count == 1) {
        $message = "Hi ".$LoginId;
        $_SESSION['message']=$message;
        $_SESSION['arrResult']=$arrResult;
        unset($_SESSION['relogin']);
        
        $UserId = $arrResult[0];
        $result1 = fnCheckStsAdmin($UserId);
        $arrResult1 = mysql_fetch_array($result1);
        $StsAdmin = $arrResult1[0];
        echo "Sts Admin: ".$StsAdmin;
        
        if ($StsAdmin == 1) {
            // admin
            header("location: ../ui/admin/adminFrame.php");
        } else {
            // cek user group nya...
            header("location: ../ui/user/oldUser.php");
        }
        
//        if ($UserGroup == 1) {
//            // admin
//            //header("location: ../ui/admin/menuAdmin.php");
//            header("location: ../ui/admin/adminFrame.php");
//        } else if ($UserGroup == 4) {
//            // reviewer
//            header("location: ../ui/reviewer/review.php");
//        } else {
//            // peserta (2), pembicara (3)
//            header("location: ../ui/user/oldUser.php");
//        }
    } else {
        $message="Your Login or Password is Invalid";
        $_SESSION['message']=$message;
        $_SESSION['relogin']="Relogin";
        header("location: ../index.php?message=$message");
    }
}

?>
